package com.spider.silence.job;

import com.spider.silence.downloader.TianFuForumDownLoader;
import com.spider.silence.pool.TianFuForumDownLoaderPool;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.StatefulJob;

import java.util.List;

/**
 * Created by Administrator on 2017/1/11 0011.
 */
public class TianFuForumJob implements StatefulJob {

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        TianFuForumDownLoaderPool downLoaderPool = null;
        TianFuForumDownLoader downLoader = null;
        try{
            //初始化天府新区下载池
            downLoaderPool = TianFuForumDownLoaderPool.getInstance();
            //初始化任务队列
            downLoader = (TianFuForumDownLoader) downLoaderPool.fetchDownLoader(1000);

            List<String> urlList = downLoader.getUrl();
            //生成任务队列
            downLoader.generateTask(urlList);
        }catch (Exception e){
             e.printStackTrace();
        }finally{
            if(downLoader !=null) {
                downLoaderPool.releaseDownLoader(downLoader);
            }
        }

    }
}
